package szcg.scheduled.service.config.quartz;

import org.quartz.impl.StdSchedulerFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;


@Configuration
public class QuartzConfig {

    private static final Logger logger = LoggerFactory.getLogger(QuartzConfig.class);

    @Autowired
    JobFactory jobFactory;

    @Bean(name = {"SchedulerFactoryBean"})
    public SchedulerFactoryBean scheduler() {
        try {
            logger.warn("=======>Scheduler初始化了<=======");
            SchedulerFactoryBean schedulerFactoryBean = new SchedulerFactoryBean();
            schedulerFactoryBean.setJobFactory(jobFactory);
            StdSchedulerFactory schedulerFactory = new StdSchedulerFactory();
            schedulerFactoryBean.setSchedulerFactory(schedulerFactory);
            return schedulerFactoryBean;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }


}
